package com.ssh.server;

import com.ssh.dao.HappyDao;
import com.ssh.entity.Happy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
@Service
@Scope("prototype")

public class HappyServerImpl implements HappyServer{
    @Autowired
    private HappyDao happyDao = null;
    @Transactional
    public List<Happy> getAllHappy() {
        List<Happy> happyList = happyDao.getAllhappy();

        for (Happy u:happyList){
            if (u.getAge()>30){
                u.setStatus("您已超龄");
            }else{
                u.setStatus("你还小呢");
            }
        }
        return happyList;
    }
    @Transactional
    public boolean isWin(Integer id) {
        Happy happy = happyDao.getHappy(id);
        if (happy==null){
            return false;
        }if (happy.getSex()!=1){
            return false;
        }if (happy.getAge()>=33||happy.getAge()<=30){
            return true;
        }else{
            return false;
        }
    }
}
